<?php
@ob_start();
@session_start();
include('../function/config.php');
include("../connect/connect.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $config['title'];?></title>
<link rel="stylesheet" href="style.css" type="text/css" />
<link rel="shortcut icon" href="../image/Letter-T.ico" />
<script language="javascript">
function IsNumeric(sText,obj)
{
	var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      {
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   		if(IsNumber==false){
			alert("กรอกได้เฉพาะตัวเลขนะคะ");
			obj.value=sText.substr(0,sText.length-1);
		}
   }
</script>

</head>
<?php
if(trim($_POST["table"]) != "")
{
	
	$tQuery = mysql_query("SELECT table_status_table FROM table_status WHERE table_status_table = '".$_POST["table"]."'");
	$numrows = mysql_num_rows($tQuery);
	
	if($numrows>='1'){
		$tabless = "หมายเลขโต๊ะ,เลขห้อง นี้มีอยู่แล้วกรุณาเลือกโต๊ะอื่นค่ะ";
	} else {
	$Query = mysql_query("UPDATE table_status SET table_status_table = '".$_POST["table"]."' WHERE table_status_table = '".$_GET['table']."'");

	$Query2 = mysql_query("UPDATE sale_session SET sale_session_table = '".$_POST["table"]."' WHERE sale_session_table = '".$_GET['table']."'");
	
	$Query3 = mysql_query("UPDATE member_non_session SET member_non_session_table = '".$_POST["table"]."' WHERE member_non_session_table = '".$_GET['table']."'");
	
	$Query4 = mysql_query("UPDATE member_session SET member_session_table = '".$_POST["table"]."' WHERE member_session_table = '".$_GET['table']."'");
	
	$_SESSION["table"]=$_POST["table"];
	session_write_close();
	header("location:manage_list.php");
	exit();
	}
}
?>
<script>
function setFocus(){
document.form1.table.focus();
}

</script>
<body  onload="setFocus()">
<p align="center"><h2 align="center">กรุณาใส่หมายเลขโต๊ะ,เลขห้อง ที่ต้องการแก้ไข</h2>
<form id="form1" name="form1" method="post" action="">
  <div align="center">
    <p>
      <input name="table" type="text" id="table" style="height:40px; width:200px; font-size:30px; color:#0000FF" autocomplete="off" />
    </p>
    <p>
      <input type="submit" name="Submit" value="ตกลง" style="height:40px; width:100px; font-size:25px"/>
      <input name="cancel" type="button" id="cancel" value="ยกเลิก" onclick="window.location='manage_list.php'" style="height:40px; width:100px; font-size:25px"/>
    </p>
  </div>
</form>
</p>
<center><font color="#FF0000" size="5"><?php echo $tabless; ?></font></center>
</body>

</html>
